//
//  LCMoreStrategyController.m
//  LendCash
//
//  Created by Mac mini on 2018/5/24.
//  Copyright © 2018年 zt. All rights reserved.
//

#import "LCMoreStrategyController.h"

@interface LCMoreStrategyController ()

@end

@implementation LCMoreStrategyController
{
    NSMutableArray *strategyArray;
}

-(instancetype)initWithStyle:(UITableViewStyle)style{
    return [super initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    strategyArray = [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"Strategy" ofType:@"plist"]];
    [self.tableView reloadData];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return strategyArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   
    if ([strategyArray[section][@"status"] boolValue] == YES) {
        return 1;
    }
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
    view.backgroundColor = [UIColor whiteColor];
    
    UILabel *leftLab = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, SCREEN_W-50, 40)];
    leftLab.text = strategyArray[section][@"title"];
    leftLab.font = BASE_FONT;
    [view addSubview:leftLab];
    
    UILabel *arrow = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_W-30, 10, 20, 20)];
    arrow.text = @">";
    [view addSubview:arrow];
    view.userInteractionEnabled = YES;
    [view setTag:section];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [view addGestureRecognizer:tap];
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGSize size = [BFPublicDefTool textViewTextFont:BASE_FONT andText:strategyArray[indexPath.section][@"content"] Weight:SCREEN_W-40 andHeight:1000];
    
    return size.height+20;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"identifier"];
    cell.backgroundColor = [UIColor lightGrayColor];
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, SCREEN_W-10, cell.frame.size.height-10)];
    lab.font = BASE_FONT;
    lab.text = strategyArray[indexPath.section][@"content"];
    lab.numberOfLines = 0;
    [cell addSubview:lab];
    // Configure the cell...
    
    return cell;
}
 
 -(void)tap:(UITapGestureRecognizer *)tap{
     NSInteger tag = tap.view.tag;
     BOOL bol = [strategyArray[tag][@"status"] boolValue];
     [strategyArray[tag] setObject:[NSNumber numberWithBool:!bol] forKey:@"status"];
     [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:tag] withRowAnimation:UITableViewRowAnimationNone];
 }
 


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
